<!DOCTYPE html>
<html>
<head>
    <title>查看</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../../Css/style.css" />
    <script type="text/javascript" src="../../Js/jquery.js"></script>
    <script type="text/javascript" src="../../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../../Js/ckform.js"></script>
    <script type="text/javascript" src="../../Js/common.js"></script>
    <script type="text/javascript" src="../../Js/ckeditor/ckeditor.js"></script>
 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        img{
            width: 120px;
            height: 110px;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }

    </style>
    <script type="text/javascript">
    $(function () {       
		$('#backid').click(function(){
				window.location.href="index.html";
		 });
    });
    </script>
</head>
<body>
<form action="index.html" method="post" class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td width="10%" class="tableleft">药品编号</td>
        <td name="drId"></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">图片</td>
        <!--<td><img name="drUrl" src="../../Images/1.png"/></td>-->
        <td><img name="drUrl" /></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">进口价(元)</td>
        <td name="drInprice">2元</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">出售价(元)</td>
        <td name="drOutprice">128.9元</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">药品名称</td>
        <td name="drName"></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">药品类型</td>
        <td name="drType"></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">简单描述</td>
        <td name="drSimdesc">用于普通感冒</td>
    </tr>

    <tr>
        <td width="10%" class="tableleft">保质期(月)</td>
        <td name="drExpirationdate">12</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">详细描述</td>
        <td name="drDetadesc">该药仅用于普通的流行性感冒,孕妇小孩慬用……</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">生产厂商</td>
        <td name="drFactory">哈药六厂生产</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">服用说明</td>
        <td name="drDirection">一次两粒一日三次</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">库存</td>
        <td name="drNumber">3000</td>
    </tr>
	<tr>
        <td width="10%" class="tableleft">备注</td>
        <td name="drRemark">暂无服用后不良记录</td>
	</tr>
    <tr>
        <td colspan="2">
			<center>
				<button type="button" class="btn btn-success" id="returnList">返回列表</button>
			</center>
		</td>
    </tr>
</table>
</form>
</body>

<script type="text/javascript">

    String.prototype.GetValue= function(para) {
        let reg = new RegExp("(^|&)"+ para +"=([^&]*)(&|$)");
        let r = this.substr(this.indexOf("\?")+1).match(reg);
        if (r!=null) return unescape(r[2]); return null;
    }

    $(function () {
        let url = document.location.toString();
        let drId=url.GetValue("drId");
        let pageNum=url.GetValue("pageNum");

        if (drId !== ""){
            queryById(drId);
        }

        //返回
        $('#returnList').click(function () {
            window.location.href = "index.html?pageNum="+pageNum;
        });
    });

    function queryById(drId){
        $.ajax({
            type: "GET",
            url: "/drug/"+drId,
            data: "",
            success: function (vo) {
                let obj = vo.obj;
                $("td[name='drId']").html(obj.drId);
                $("td[name='drInprice']").html(obj.drInprice);
                $("td[name='drOutprice']").html(obj.drOutprice);
                $("td[name='drName']").html(obj.drName);
                $("td[name='drSimdesc']").html(obj.drSimdesc);
                $("td[name='drExpirationdate']").html(obj.drExpirationdate);
                $("td[name='drDetadesc']").html(obj.drDetadesc);
                $("td[name='drFactory']").html(obj.drFactory);
                $("td[name='drDirection']").html(obj.drDirection);
                $("td[name='drNumber']").html(obj.drNumber==null?"无货":obj.drNumber);
                $("td[name='drRemark']").html(obj.drRemark);

                //药物图片处理
                var drUrlNode = $("img[name='drUrl']");
                if (obj.drUrl == null){
                    drUrlNode.addClass("hidden");
                    drUrlNode.parent().html("未上传图片");
                }else{
                    drUrlNode.attr("src","../../Images/uploadFile/drug/"+obj.drUrl);
                }

                //药物类型处理
                let drType;
                switch (obj.drType){
                    case "1": drType = "中药";break;
                    case "2": drType = "西药";break;
                    case "3": drType = "处方";break;
                    default:
                        drType = "未分类";break;
                }
                $("td[name='drType']").html(drType);
            }
        });
    }

</script>

</html>